home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / cmln0186.arc / ARTINT2.LTG < prev    next >
Text File  |  1986-12-20  |  768b  |  18 lines

  1.  
  2.  
  3.                             Listing 2  
  4.                      Pattern Matcher in Lisp
  5.  
  6.  
  7.  (DEFUN MATCH (LAMBDA (P E)
  8.     (COND ((OR (EQUAL P E)                     ;Identical things match
  9.                (MEMBER P '(? *))) T)           ;? and * match anything
  10.           ((OR (ATOM P) (ATOM E)) NIL)         ;No match now if not both lists
  11.           ((EQUAL (CAR P) '*)                  ;If pattern starts with *, we
  12.            (OR (MATCH (CDR P) (CDR E))         ; match if both tails match or
  13.                (MATCH P (CDR E))))             ; if P (with *) matches tail of E
  14.           (T (AND (MATCH (CAR P) (CAR E))      ;Else we match if heads match
  15.                   (MATCH (CDR P) (CDR E))))))  ; and tails match
  16.  
  17.  
  18.